package lanou3g.myfirstapp36kr.fragment;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;
import lanou3g.myfirstapp36kr.BuildConfig;
import lanou3g.myfirstapp36kr.R;
import lanou3g.myfirstapp36kr.base.BaseFragment;

/**
 * Created by dllo on 16/8/30.
 */
public class RigistFragment extends BaseFragment {
    private EditText editTextAccount;
    private EditText editTextPassWord;
    private Button buttonRegist;
    @Override
    protected int getLayout() {
        return R.layout.fragment_regist;
    }

    @Override
    protected void initView(View view) {
        editTextAccount = (EditText) view.findViewById(R.id.et_phone_num);
        editTextPassWord = (EditText) view.findViewById(R.id.et_phone_pass);
        buttonRegist = (Button) view.findViewById(R.id.btn_get_sure);

    }

    @Override
    protected void initData() {
        buttonRegist.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                String accountStr = editTextAccount.getText().toString();
                String passwordStr = editTextPassWord.getText().toString();
                BmobUser bmobUser = new BmobUser();
                bmobUser.setUsername(accountStr);
                bmobUser.setPassword(passwordStr);
                bmobUser.signUp(new SaveListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        if (e == null){
                            Toast.makeText(RigistFragment.this.getActivity(), "注册成功", Toast.LENGTH_SHORT).show();
                            editTextAccount.setText("");
                            editTextPassWord.setText("");
                            

                        }else {
                            if (BuildConfig.DEBUG) Log.d("RigistFragment", "e:" + e);
                        }

                    }
                });
            }
        });


    }
}
